package xyz.lwm.lazycat.web.proxy;

import lombok.AllArgsConstructor;
import xyz.lwm.lazycat.utility.Assert;
import xyz.lwm.lazycat.web.handle.Context;
import xyz.lwm.lazycat.web.handle.Handler;
import xyz.lwm.lazycat.web.settings.ProxyHttpSetting;

/**
 * 转发请求, 反向代理
 *
 * @author lwm
 */
@AllArgsConstructor
class ProxyHandler implements Handler {

    // proxy http setting
    private final ProxyHttpSetting proxy;

    // proxy client
    private final ProxyClient proxyClient;

    @Override
    public void handle(Context ctx) {
        Assert.isTrue(proxy.getListenPort() > 0, "listen port must > 0");
        proxyClient.proxyHttp(ctx, proxy);
    }

}
